﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KM.ENT;
using KM.BUS;
using KM.Models;
using CORE;

namespace KM.Areas.REM.Controllers.SanPham
{
    public class SanPhamController : Controller
    {
        //
        // GET: /REM/SanPham/
        int pageSize = 9;
        public PartialViewResult DanhSach(int Id, string Name)
        {
            //lay loai san pham
            busLoaiSanPham busLSP = new busLoaiSanPham();
            entLoaiSanPham entLSP = new entLoaiSanPham();
            entLSP = busLSP.getInfo(Id);
            ViewBag.SanPham = entLSP.TenNhomSanPham;
            List<entSanPham> lst = new List<entSanPham>();
            busSanPham busSP = new busSanPham();
            PagingInfoModel page = new PagingInfoModel()
            {
                CurrentPage = Utils.getIntQuery("page") == 0 ? 1 : Utils.getIntQuery("page"),
                recordPerPage = pageSize
            };
            if (Id != null)
            {
                lst = busSP.getAll(Id, ref page);
            }
            ViewBag.Id = Id;
            ViewBag.Name = Name;
            ViewBag.page = page;

            //lay titile

            busConfig busCF = new busConfig();
            entConfig entCF = new entConfig();
            entCF = busCF.getInfo(1);
            ViewBag.Title = entCF.Title;
            ViewBag.keywords = entCF.Keyword;
            ViewBag.description = entCF.Description;

            return PartialView(lst);
        }

        public PartialViewResult SanPhamMoi(int type)
        {
            busSanPham busSP = new busSanPham();
            List<entSanPham> lst = new List<entSanPham>();

            switch (type)
            {
                case Constans.SANPHAMMOI:
                    ViewBag.SanPham = "SẢN PHẨM MỚI";
                    lst = busSP.getListByType(type, Constans.SOSANPHAMHIENTHI);
                    break;
                case Constans.SANPHAMNOIBAT:
                    ViewBag.SanPham = "SẢN PHẨM NỘI BẬT";
                    lst = busSP.getListByType(type, Constans.SOSANPHAMHIENTHI);
                    break;

            }
            return PartialView(lst);
        }
        public PartialViewResult SanPhamCungLoai(int Id)
        {
            busSanPham busSP = new busSanPham();
            List<entSanPham> lst = new List<entSanPham>();


            lst = busSP.getSpCungLoai(Id);

            return PartialView(lst);
        }
        public ActionResult ChiTiet(int Id)
        {
            busSanPham busSP = new busSanPham();
            entSanPham entSP = new entSanPham();
            entSP = busSP.getInfo(Id);
            ViewBag.SanPham = "SẢN PHẨM";

            busConfig busCF = new busConfig();
            entConfig entCF = new entConfig();
            entCF = busCF.getInfo(1);
            if (entSP.Title == "")
            {
                ViewBag.Title = entCF.Title;
                ViewBag.keywords = entCF.Keyword;
                ViewBag.description = entCF.Description;
            }
            return View(entSP);
        }

        public PartialViewResult GetSlide()
        {
            busSanPham busSP = new busSanPham();
            List<entSanPham> lst = new List<entSanPham>();
            lst = busSP.getSlide();
            return PartialView(lst);
        }


    }
}
